package cn.javadog.algorithm.e1_100;


/**
 * 回文数
 * https://leetcode-cn.com/problems/palindrome-number/
 * @author Sprite
 */
public class Algorithm9 {
	public static void main(String[] args) {
		System.out.println(isPalindrome(123));
		System.out.println(isPalindrome(1234321));
		System.out.println(isPalindrome(1233321));
		System.out.println(isPalindrome(-1233321));
		System.out.println(isPalindrome(0));
	}


	public static boolean isPalindrome(int x) {
		if (x<0) return false;

		String s = String.valueOf(x);
		int leftIdx = 0;
		int rightIdx = s.length()-1;
		while (rightIdx-leftIdx >= 0){
			if (s.charAt(leftIdx) != s.charAt(rightIdx)) return false;
			leftIdx++;
			rightIdx--;
		}
		return true;
	}
}
